package dontCare.gwtester.client.gwt;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

import dontCare.gwtester.client.GWTesterEP;
import dontCare.gwtester.client.tool.SourceUrl;
import dontCare.gwtester.client.tool.UnitWidget;

//Refactory 改名字、改 output 寫法
public class Gwt extends UnitWidget{
	private VerticalPanel panel = new VerticalPanel();
	public Gwt(){
		String result = "[client] GWT.isClient() = " + GWT.isClient()+
				", GWT.isScript() = " + GWT.isScript();
		panel.add(new Label(result));
		GWTesterEP.rpc.gwtMethod(new AsyncCallback<String>() {
			@Override
			public void onSuccess(String result) {
				panel.add(new Label("[server] "+result));
			}
			
			@Override
			public void onFailure(Throwable caught) {}
		});
		
		this.initWidget(panel);
	}

	@Override
	public List<String> getSourceUrl() {
		ArrayList<String> result = new ArrayList<String>();
		result.add(SourceUrl.genJava(this.getClass()));
		result.add(SourceUrl.genUiXml(this.getClass()));
		return result;
	}

	@Override
	public HTML getDescription() {
		return new HTML("GWT method 測試");
	}

	@Override
	public String getName() {
		return "GWT mthod";
	}

}
